﻿package app.view.components.sections.russia 
{
	import app.model.RemoteProxy;
	import app.model.types.SectionType;
	import app.model.vo.SectionVO;
	import app.view.components.buttons.GlamurBtnBase;
	import app.view.components.guiDima.keyboard.KeyBoardWithInputFieldDBase;
	import app.view.components.guiDima.slideShowD.Image;
	import app.view.components.guiDima.switchContent.SwitchContentDBase;
	import app.view.components.sections.LabeledSectionBase;
	import app.view.events.UIEvent;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.ui.Mouse;
	
	/**
	 * 3. О РОССИИ
	 * @author Dmitryi_Koruagin, icq:585466579, dmitryikoruagin@mail.ru, skype: ok_ru1
	 */
	public class RussiaAboutDBase extends LabeledSectionBase
	{
		
		public var interactivMap_Btn:GlamurBtnBase;
		public var history_Btn:GlamurBtnBase;
		public var cyltyra_Btn:GlamurBtnBase;
		public var itrectingRussia_Btn:GlamurBtnBase;
		
		private var _image:Image;
		
		private var _btns:/*GlamurBtnBase*/Array;
		
		public function RussiaAboutDBase() 
		{
			super();
			
		}
		
		override protected function init():void
		{
			super.init();
			
			
			_btns = [interactivMap_Btn, history_Btn, cyltyra_Btn,itrectingRussia_Btn];
		}
		
		private function build():void
		{
			_image = new Image(1680, 1050, Image.RESIZE_NONE, Image.ALIGN_NONE, 0, 0, false, 1, false);
			addChildAt(_image,0);
			////trace('url',RemoteProxy.DOMEN+_data.data.flash[1].flash[1].flash_path);
			if (_data) 
			{
				if (_data.data.flash[1].flash[1].flash_path!=undefined && _data.data.flash[1].flash[1].flash_path!='') 
				{
					_image.loadImage(RemoteProxy.DOMEN+_data.data.flash[1].flash[1].flash_path);
				};
			};
			
		};
		
		private function setEvents():void
		{
			interactivMap_Btn.addEventListener(MouseEvent.CLICK, onClickInteractivMap);
			history_Btn.addEventListener(MouseEvent.CLICK, onClickHistory);
			cyltyra_Btn.addEventListener(MouseEvent.CLICK, onCLickCyltyra);
			itrectingRussia_Btn.addEventListener(MouseEvent.CLICK, onClickIntrectingRussia);
			
			
			for (var i:int = 0; i < _btns.length; i++) 
			{
				_btns[i].addEventListener(MouseEvent.ROLL_OVER, onRollOver);
				_btns[i].addEventListener(MouseEvent.ROLL_OUT, onRollOut);
			}
		}
		
		private function onRollOver(e:MouseEvent):void 
		{
			Mouse.show();
			
		}
		
		private function onRollOut(e:MouseEvent):void 
		{
			Mouse.hide();
			
		}
		
		private function removeEvents():void
		{
			interactivMap_Btn.removeEventListener(MouseEvent.CLICK, onClickInteractivMap);
			history_Btn.removeEventListener(MouseEvent.CLICK, onClickHistory);
			cyltyra_Btn.removeEventListener(MouseEvent.CLICK, onCLickCyltyra);
			itrectingRussia_Btn.removeEventListener(MouseEvent.CLICK, onClickIntrectingRussia);
			
			for (var i:int = 0; i < _btns.length; i++) 
			{
				_btns[i].removeEventListener(MouseEvent.ROLL_OVER, onRollOver);
				_btns[i].removeEventListener(MouseEvent.ROLL_OUT, onRollOut);
			}
		}
		
		override public function onDestroy():void 
		{
			// чистим что тут есть и вызываем супера
			removeEvents();
			
			interactivMap_Btn.destroy();
			history_Btn.destroy();
			cyltyra_Btn.destroy();
			itrectingRussia_Btn.destroy();
			
			if (_image)
			{
				_image.destroy();
				removeChild(_image);
				_image = null;
			}
			
			super.onDestroy();
		};
		
		override public function get data():Object { return _data; };
		
		override public function set data(value:Object):void 
		{
			super.data = value;
			
			////trace('data!!!+++', _data.data);
			
			interactivMap_Btn.setLang(_data.lang);
			history_Btn.setLang(_data.lang);
			cyltyra_Btn.setLang(_data.lang);
			itrectingRussia_Btn.setLang(_data.lang);
			
			setEvents();
			
			build();
		};
		
		/**
		 * переход в интерактивную карту
		 * @param	e
		 */
		private function onClickInteractivMap(e:MouseEvent):void 
		{
			removeEvents();
			
			// переходим далее
				
			var obj:SectionVO = new SectionVO();
			obj.id = SectionType.PAGE_RUSSIA_MAP;
			obj.currentId = id;
			obj.params = null;
			
			var ev:UIEvent = new UIEvent(UIEvent.SECTION_CHANGE);
			ev.data = obj;
			dispatchEvent(ev);
			
		}
		
		/**
		 * переход в историю
		 * @param	e
		 */
		private function onClickHistory(e:MouseEvent):void 
		{
			removeEvents();
			
			// переходим далее
				
			var obj:SectionVO = new SectionVO();
			obj.id = SectionType.PAGE_RUSSIA_HISTORY;
			obj.currentId = id;
			obj.params = null;
			
			var ev:UIEvent = new UIEvent(UIEvent.SECTION_CHANGE);
			ev.data = obj;
			dispatchEvent(ev);
			
		}
		
		/**
		 * переход в культуру
		 * @param	e
		 */
		private function onCLickCyltyra(e:MouseEvent):void 
		{
			removeEvents();
			
			// переходим далее
				
			var obj:SectionVO = new SectionVO();
			obj.id = SectionType.PAGE_RUSSIA_CALTURE;
			obj.currentId = id;
			obj.params = null;
			
			var ev:UIEvent = new UIEvent(UIEvent.SECTION_CHANGE);
			ev.data = obj;
			dispatchEvent(ev);
			
		}
		
		/**
		 * переход в интересное о России
		 * @param	e
		 */
		private function onClickIntrectingRussia(e:MouseEvent):void 
		{
			removeEvents();
			
			// переходим далее
				
			var obj:SectionVO = new SectionVO();
			obj.id = SectionType.PAGE_RUSSIA_ABOUT_INTRESTING;
			obj.currentId = id;
			obj.params = null;
			
			var ev:UIEvent = new UIEvent(UIEvent.SECTION_CHANGE);
			ev.data = obj;
			dispatchEvent(ev);
			
		}
	}

}